package day01;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;

class FileUtils2{
    public static void copyUrlFile(File srcFile,File targetFile) throws IOException {
        BufferedInputStream bin = new BufferedInputStream(
                new FileInputStream(srcFile)
        );
        BufferedOutputStream bout = new BufferedOutputStream(
                new FileOutputStream(targetFile)
        );
        byte[] buff = new byte[1024];
        int len = -1;
        System.out.println("开始");
        while((len=bin.read(buff))>0) {
            bout.write(buff,0,len);
            bout.flush();
        }
        System.out.println("结束");
        bin.close();
        bout.close();
    }
}

public class BufferInputStreamDemo01 {
    public static void main(String[] args) throws URISyntaxException, IOException {
        File srcFile = new File(new URI("https://cn.bing.com/images/search?view=detailV2&ccid=L%2fQp%2fUQn&id=4B45838EE8EFEB678EAE6071787DC8655806A6B3&thid=OIP.L_Qp_UQnBWQBRHqEDGtf6AHaE7&mediaurl=https%3a%2f%2fimg95.699pic.com%2fphoto%2f60017%2f2391.jpg_wh860.jpg&exph=573&expw=860&q=tupian&simid=608049361613584936&FORM=IRPRST&ck=C19AA73EF42120E9D98A18470CEAE827&selectedIndex=0&itb=0&idpp=overlayview&ajaxhist=0&ajaxserp=0"));
        File targetFile = new File("D:\\1\\img-1.jpg");
        FileUtils2.copyUrlFile(srcFile,targetFile);
    }
}
